package org.vectrics.common.html;

import org.apache.ecs.html.Font;
import org.apache.ecs.html.TD;
import org.apache.log4j.Logger;
import org.vectrics.SystemException;
import org.vectrics.common.util.StringUtils;


public class Cell extends TD {
	
	private static final long serialVersionUID = 4268286011323222083L;
	
	private Logger log = Logger.getLogger(this.getClass());
	int colSpan = 1;
    private String defaultFontClass = null;

    public Cell() {
        setVAlign("TOP");
    }

    public TD setColSpan(int colSpan) {
    	this.colSpan = colSpan;
    	return super.setColSpan(colSpan);
    }

    public TD setColSpan(String colSpan) {
    	this.colSpan = Integer.parseInt(colSpan);
    	return super.setColSpan(Integer.parseInt(colSpan));
    }
    
    public Font addText(String styleClass, String text) {
    	Font textElement = TextHelper.getFont(styleClass, text);
    	this.addElement(textElement);
    	return(textElement);
    }
    
    public void addText(String text) {
    	if (log.isDebugEnabled())
    		log.debug("row.defaultFontClass=" + this.defaultFontClass);
    	
    	if (this.defaultFontClass == null) {
    		throw new SystemException("Cannot use addText(text) without assigning defaultFontClass");
    	}
    	if (StringUtils.isNullOrBlank(text))
        	this.addText(this.defaultFontClass, "&nbsp;");
    	else
    		this.addText(this.defaultFontClass, text);
    }
    
	public int getColSpan() {
		return colSpan;
	}

	public String getDefaultFontClass() {
		return defaultFontClass;
	}

	public void setDefaultFontClass(String defaultFontClass) {
		this.defaultFontClass = defaultFontClass;
	}
	
	public TD setBgColor(String color) {
		return super.setBgColor(color);
	}

}